package com.example.gitpart03; // 修正包名

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivity extends AppCompatActivity {
    // 默认账号密码
    private static final String DEFAULT_ACCOUNT = "marui";
    private static final String DEFAULT_PASSWORD = "202422431419";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // 处理系统栏Insets
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        // 获取账号密码输入框
        EditText etAccount = findViewById(R.id.et_account);
        EditText etPassword = findViewById(R.id.et_password);

        // 登录按钮点击事件
        Button btnLogin = findViewById(R.id.btn_login);
        btnLogin.setOnClickListener(v -> {
            String account = etAccount.getText().toString().trim();
            String password = etPassword.getText().toString().trim();

            // 校验账号密码
            if (account.isEmpty() || password.isEmpty()) {
                Toast.makeText(this, "账号和密码不能为空", Toast.LENGTH_SHORT).show();
            } else if (DEFAULT_ACCOUNT.equals(account) && DEFAULT_PASSWORD.equals(password)) {
                Toast.makeText(this, "登录成功", Toast.LENGTH_SHORT).show();
                // 可添加登录成功后的跳转逻辑
            } else {
                Toast.makeText(this, "账号或密码错误", Toast.LENGTH_SHORT).show();
            }
        });

        // 注册按钮点击事件
        Button btnRegister = findViewById(R.id.btn_register);
        btnRegister.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, RegisterSuccessActivity.class);
                startActivity(intent);
            }
        });
        Button btnlogin = findViewById(R.id.btn_login);
        EditText editText1 = findViewById(R.id.et_account);
        EditText editText2 = findViewById(R.id.et_password);
        btnLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if ("marui".equals(editText1.getText().toString()) &&
                        "202422431419".equals(editText2.getText().toString())) {
                    // 验证通过，执行跳转逻辑
                    Intent intent = new Intent(MainActivity.this, StartHome.class);
                    startActivity(intent);
                } else {
                    // 验证失败，提示用户
                    Toast.makeText(MainActivity.this, "用户名或者密码错误", Toast.LENGTH_SHORT).show();
                }
            }
        });

    }
}